import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from "@/router";
import { setupStore, usePermissionStore } from "@/store";
import { setupPermission } from "@/plugins/permission";
// 导入自定义主题 黄色按钮 - 必须在Element Plus样式前导入
// import './styles/element-variables.scss'
// 导入 Element Plus
import ElementPlus from 'element-plus'
// 导入 Element Plus 样式
import 'element-plus/dist/index.css'
// 导入 Element Plus 图标（可选，按需使用）
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import './theme/element-variables.scss'
// 导入中文语言包
import zhCn from 'element-plus/es/locale/lang/zh-cn'

const app = createApp(App)

// 全局注册图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
// 全局配置Element Plus，指定中文语言
app.use(ElementPlus, { locale: zhCn })

// 全局注册 状态管理(store)
setupStore(app);

const permissionStore = usePermissionStore();
const accessRoutes = await permissionStore.generateRoutes();
accessRoutes.forEach(route => router.addRoute(route));
permissionStore.setDynamicAdded(true);

// 全局注册 路由
app.use(router);
// 注册动态路由
setupPermission();
app.mount('#app')
